package com.cxy.datawarehouse.exception;


import com.cxy.datawarehouse.response.Result;
import com.cxy.datawarehouse.response.ResultStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author admin
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(value = BizException.class)
    public Result<String> exceptionHandler(BizException e) {
        log.error("全局异常处理 msg:{} error:", e.getMessage(), e);
        e.printStackTrace();
        return Result.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(value = Exception.class)
    public Result<String> exceptionHandler(Exception e) {
        log.error("全局异常处理 msg:{} error:", e.getMessage(), e);
        e.printStackTrace();
        return Result.error(ResultStatus.BAD_REQUEST, e.getMessage());
    }
}
